package controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import service.UserService;

import java.util.Map;
@Controller

@RestController
@CrossOrigin// 允许前端域名访问
@RequestMapping("/doctor")
public class DoctorLoginController {

    private final UserService userService;

    public DoctorLoginController(UserService userService) {
        this.userService = userService;
    }

    /**
     * 通用登录接口
     * 请求体示例：
     * {
     *   "userName": "zhangsan",
     *   "password": "123456",
     *   "userRole": "doctor"
     * }
     */
    @PostMapping("/login")
    public Map<String, Object> login(@RequestBody Map<String, String> loginParam) {
        String userName = loginParam.get("userName");
        String password = loginParam.get("password");
        String userRole = loginParam.get("userRole");

        return userService.login(userName, password, userRole);


    }
}